Skip to content

Comments

Feature/improve gewechat message#327

Open
samqin123 wants to merge 6 commits intohanfangyuan4396:masterfrom
PancrePal-xiaoyibao:feature/improve-gewechat-message
Open

Feature/improve gewechat message#327
samqin123 wants to merge 6 commits intohanfangyuan4396:masterfrom
PancrePal-xiaoyibao:feature/improve-gewechat-message

Conversation

@samqin123
Copy link

现有代码中hello插件,无法发送。修改了gewe_channel.py,现在可以正常了。
image

@samqin123
Copy link
Author

` elif msg_type == 10002: # Group System Message
if self.is_group:
content = msg['Data']['Content']['string']
logger.debug(f"解析获取消息内容:{content}")
if any(note_bot_join_group in content for note_bot_join_group in notes_bot_join_group): # 邀请机器人加入群聊
logger.warn("机器人加入群聊消息,不处理~")
pass
elif any(note_join_group in content for note_join_group in notes_join_group): # 若有任何在notes_join_group列表中的字符串出现在NOTE中
try:
# Extract the XML part after the chatroom ID
xml_content = content.split(':\n', 1)[1] if ':\n' in content else content
root = ET.fromstring(xml_content)
logger.debug(f"解析除掉wxids的内容体:{xml_content}")
# Navigate through the XML structure
sysmsgtemplate = root.find('.//sysmsgtemplate')
if sysmsgtemplate is not None:
content_template = sysmsgtemplate.find('.//content_template')
if content_template is not None:
template_type = content_template.get('type')
if template_type in {'tmpl_type_profile','tmpl_type_profilewithrevoke','tmpl_type_profilewithrevokeqrcode'}:
#if (content_template is not None) and ( content_template.get('type') == 'tmpl_type_profile' or content_template.get('type') == 'tmpl_type_profilewithrevoke' ):
template = content_template.find('.//template')
if template is not None and ('加入了群聊' in template.text or '加入群聊' in template.text):
self.ctype = ContextType.JOIN_GROUP

                                # Extract inviter info
                                inviter_link = root.find(".//link[@name='username']//nickname")
                                inviter_nickname = inviter_link.text if inviter_link is not None else "未知用户"

                                # Extract invited member info
                                invited_link = root.find(".//link[@name='names']//nickname")
                                invited_nickname = invited_link.text if invited_link is not None else "未知用户"
                                if invited_link is None:
                                    invited_link = root.find(".//link[@name='adder']//nickname")
                                    invited_nickname = invited_link.text if invited_link is not None else "未知用户"

                                self.content = f'"{inviter_nickname}"邀请"{invited_nickname}"加入了群聊'
                                logger.debug(f"解析加入群聊消息类型{self.content}")
                                self.actual_user_nickname = invited_nickname
                                # 获取群聊或好友的名称
                                brief_info_response = self.client.get_brief_info(self.app_id, [self.other_user_id])
                                if brief_info_response['ret'] == 200 and brief_info_response['data']:
                                    brief_info = brief_info_response['data'][0]
                                    self.other_user_nickname = brief_info.get('nickName', '')
                                    # 获取群昵称
                                    if not self.other_user_nickname:
                                        self.other_user_nickname = self.other_user_id
                                logger.debug(f"解析消息群组名称{self.other_user_nickname}")
                                return

                            else:
                                logger.debug(f"加入了群聊不在template中 {template}")
                        else:
                            logger.debug(f"template_type-{template_type} 不在 tmpl_type_profile tmpl_type_profilewithrevoke 中")                                            
                    else:
                        logger.debug(f"找不到.//content_template")
                else:
                    logger.debug(f"找不到.//sysmsgtemplate")
            except ET.ParseError as e:
                logger.error(f"[gewechat] Failed to parse group join XML: {e}")
                # Fall back to regular content handling
                pass
else:
    raise NotImplementedError("Unsupported message type: Type:{}".format(msg_type))`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant